package com.wkq.util.transformer

import android.view.View
import androidx.viewpager2.widget.ViewPager2

/**
 *
 *@Author: wkq
 *
 *@Time: 2025/7/30 10:10
 *
 *@Desc:  StackPageTransformer
 */
class StackPageTransformer : ViewPager2.PageTransformer {
    private val scaleFactor = 0.8f
    private val translationFactor = 50f

    override fun transformPage(page: View, position: Float) {
        val pageWidth = page.width

        when {
            position <= 0 -> {
                page.translationX = 0f
                page.scaleX = 1f
                page.scaleY = 1f
                page.alpha = 1f
                page.elevation = 1f
            }
            position <= 1 -> {
                // 后面的页面缩小并平移，模拟堆叠
                val scale = scaleFactor + (1 - scaleFactor) * (1 - position)
                val translationX = -translationFactor * position

                page.scaleX = scale
                page.scaleY = scale
                page.translationX = translationX
                page.alpha = 1 - position * 0.5f
                page.elevation = 0f
            }
            else -> {
                page.alpha = 0f
            }
        }
    }
}
